Index: uspace/lib/ext4/libext4_directory.c
===================================================================
--- uspace/lib/ext4/libext4_directory.c	(revision b7e02600e8909779146953116f68cafa8e244b48)
+++ uspace/lib/ext4/libext4_directory.c	(revision d9bbe45b59b45f91fb35394b54013cbf7aab5774)
@@ -125,11 +125,5 @@
 	int rc;
 
-	uint64_t size;
-	aoff64_t current_block_idx;
-	aoff64_t next_block_idx;
-	uint32_t next_block_phys_idx;
-	uint32_t block_size;
-
-	size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode);
+	uint64_t size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode);
 
 	/* The iterator is not valid until we seek to the desired position */
@@ -150,7 +144,7 @@
 	}
 
-	block_size = ext4_superblock_get_block_size(it->fs->superblock);
-	current_block_idx = it->current_offset / block_size;
-	next_block_idx = pos / block_size;
+	uint32_t block_size = ext4_superblock_get_block_size(it->fs->superblock);
+	aoff64_t current_block_idx = it->current_offset / block_size;
+	aoff64_t next_block_idx = pos / block_size;
 
 	/* If we don't have a block or are moving accross block boundary,
@@ -166,4 +160,5 @@
 		}
 
+		uint32_t next_block_phys_idx;
 		rc = ext4_filesystem_get_inode_data_block_index(it->fs,
 		    it->inode_ref->inode, next_block_idx, &next_block_phys_idx);
@@ -188,7 +183,8 @@
     uint32_t block_size)
 {
+
+	it->current = NULL;
+
 	uint32_t offset_in_block = it->current_offset % block_size;
-
-	it->current = NULL;
 
 	/* Ensure proper alignment */
@@ -439,5 +435,4 @@
 {
 	int rc;
-	ext4_directory_iterator_t it;
 
 	if (!ext4_inode_is_type(fs->superblock, parent->inode,
@@ -446,4 +441,5 @@
 	}
 
+	ext4_directory_iterator_t it;
 	rc = ext4_directory_iterator_init(&it, fs, parent, 0);
 	if (rc != EOK) {
Index: uspace/lib/ext4/libext4_directory_index.c
===================================================================
--- uspace/lib/ext4/libext4_directory_index.c	(revision b7e02600e8909779146953116f68cafa8e244b48)
+++ uspace/lib/ext4/libext4_directory_index.c	(revision d9bbe45b59b45f91fb35394b54013cbf7aab5774)
@@ -130,9 +130,6 @@
 		ext4_superblock_t *sb, size_t name_len, const char *name)
 {
-	uint32_t block_size, entry_space;
-	uint16_t limit;
-	ext4_directory_dx_root_t *root;
-
-	root = (ext4_directory_dx_root_t *)root_block->data;
+
+	ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data;
 
 	if (root->info.hash_version != EXT4_HASH_VERSION_TEA &&
@@ -154,12 +151,12 @@
 	}
 
-	block_size = ext4_superblock_get_block_size(sb);
-
-	entry_space = block_size;
+	uint32_t block_size = ext4_superblock_get_block_size(sb);
+
+	uint32_t entry_space = block_size;
 	entry_space -= 2 * sizeof(ext4_directory_dx_dot_entry_t);
 	entry_space -= sizeof(ext4_directory_dx_root_info_t);
     entry_space = entry_space / sizeof(ext4_directory_dx_entry_t);
 
-    limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)&root->entries);
+    uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)&root->entries);
     if (limit != entry_space) {
     	return EXT4_ERR_BAD_DX_DIR;
@@ -187,22 +184,18 @@
 {
 	int rc;
-	uint16_t count, limit, entry_space;
-	uint8_t indirect_level;
-	ext4_directory_dx_root_t *root;
+
+	ext4_directory_dx_block_t *tmp_dx_block = dx_blocks;
+
+	ext4_directory_dx_root_t *root = (ext4_directory_dx_root_t *)root_block->data;
+	ext4_directory_dx_entry_t *entries = (ext4_directory_dx_entry_t *)&root->entries;
+
+	uint16_t limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
+	uint8_t indirect_level = ext4_directory_dx_root_info_get_indirect_levels(&root->info);
+
+	block_t *tmp_block = root_block;
 	ext4_directory_dx_entry_t *p, *q, *m, *at;
-	ext4_directory_dx_entry_t *entries;
-	block_t *tmp_block = root_block;
-	uint32_t fblock, next_block;
-	ext4_directory_dx_block_t *tmp_dx_block = dx_blocks;
-
-	root = (ext4_directory_dx_root_t *)root_block->data;
-	entries = (ext4_directory_dx_entry_t *)&root->entries;
-
-	limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
-	indirect_level = ext4_directory_dx_root_info_get_indirect_levels(&root->info);
-
 	while (true) {
 
-		count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries);
+		uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)entries);
 		if ((count == 0) || (count > limit)) {
 			return EXT4_ERR_BAD_DX_DIR;
@@ -232,8 +225,9 @@
         }
 
-		next_block = ext4_directory_dx_entry_get_block(at);
+		uint32_t next_block = ext4_directory_dx_entry_get_block(at);
 
         indirect_level--;
 
+        uint32_t fblock;
         rc = ext4_filesystem_get_inode_data_block_index(fs, inode, next_block, &fblock);
         if (rc != EOK) {
@@ -249,5 +243,6 @@
 		limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries);
 
-        entry_space = ext4_superblock_get_block_size(fs->superblock) - sizeof(ext4_directory_dx_dot_entry_t);
+        uint16_t entry_space = ext4_superblock_get_block_size(fs->superblock)
+        		- sizeof(ext4_directory_dx_dot_entry_t);
         entry_space = entry_space / sizeof(ext4_directory_dx_entry_t);
 
@@ -266,15 +261,12 @@
 
 
-static int ext4_dirextory_dx_find_dir_entry(block_t *block,
+static int ext4_directory_dx_find_dir_entry(block_t *block,
 		ext4_superblock_t *sb, size_t name_len, const char *name,
 		ext4_directory_entry_ll_t **res_entry, aoff64_t *block_offset)
 {
-	ext4_directory_entry_ll_t *dentry;
-	uint16_t dentry_len;
-	uint8_t *addr_limit;
+
 	aoff64_t offset = 0;
-
-	dentry = (ext4_directory_entry_ll_t *)block->data;
-	addr_limit = block->data + ext4_superblock_get_block_size(sb);
+	ext4_directory_entry_ll_t *dentry = (ext4_directory_entry_ll_t *)block->data;
+	uint8_t *addr_limit = block->data + ext4_superblock_get_block_size(sb);
 
 	while ((uint8_t *)dentry < addr_limit) {
@@ -297,5 +289,5 @@
 
 		// Goto next entry
-		dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
+		uint16_t dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
 
         if (dentry_len == 0) {
@@ -314,19 +306,14 @@
 		ext4_directory_dx_block_t *handle, ext4_directory_dx_block_t *handles)
 {
-	ext4_directory_dx_block_t *p;
-	uint16_t count;
-	uint32_t num_handles;
-	uint32_t current_hash;
-	block_t *block;
-	uint32_t block_addr, block_idx;
-    int rc;
-
-    num_handles = 0;
-    p = handle;
+	int rc;
+
+
+    uint32_t num_handles = 0;
+    ext4_directory_dx_block_t *p = handle;
 
     while (1) {
 
     	p->position++;
-    	count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)p->entries);
+    	uint16_t count = ext4_directory_dx_countlimit_get_count((ext4_directory_dx_countlimit_t *)p->entries);
 
     	if (p->position < p->entries + count) {
@@ -342,5 +329,5 @@
     }
 
-    current_hash = ext4_directory_dx_entry_get_hash(p->position);
+    uint32_t current_hash = ext4_directory_dx_entry_get_hash(p->position);
 
     if ((hash & 1) == 0) {
@@ -350,7 +337,9 @@
     }
 
+
     while (num_handles--) {
 
-    	block_idx = ext4_directory_dx_entry_get_block(p->position);
+    	uint32_t block_idx = ext4_directory_dx_entry_get_block(p->position);
+    	uint32_t block_addr;
     	rc = ext4_filesystem_get_inode_data_block_index(fs, inode, block_idx, &block_addr);
     	if (rc != EOK) {
@@ -358,4 +347,5 @@
     	}
 
+    	block_t *block;
     	rc = block_get(&block, fs->device, block_addr, BLOCK_FLAGS_NONE);
     	if (rc != EOK) {
@@ -379,12 +369,7 @@
 {
 	int rc;
-	uint32_t root_block_addr, leaf_block_addr, leaf_block_idx;
-	aoff64_t block_offset;
-	block_t *root_block, *leaf_block;
-	ext4_hash_info_t hinfo;
-	ext4_directory_entry_ll_t *res_dentry;
-	ext4_directory_dx_block_t dx_blocks[2], *dx_block;
 
 	// get direct block 0 (index root)
+	uint32_t root_block_addr;
 	rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, 0, &root_block_addr);
 	if (rc != EOK) {
@@ -392,4 +377,5 @@
 	}
 
+	block_t *root_block;
 	rc = block_get(&root_block, fs->device, root_block_addr, BLOCK_FLAGS_NONE);
 	if (rc != EOK) {
@@ -398,4 +384,5 @@
 	}
 
+	ext4_hash_info_t hinfo;
 	rc = ext4_directory_hinfo_init(&hinfo, root_block, fs->superblock, len, name);
 	if (rc != EOK) {
@@ -404,4 +391,6 @@
 	}
 
+	ext4_directory_dx_block_t dx_blocks[2];
+	ext4_directory_dx_block_t *dx_block;
 	rc = ext4_directory_dx_get_leaf(&hinfo, fs, inode_ref->inode, root_block, &dx_block, dx_blocks);
 	if (rc != EOK) {
@@ -410,8 +399,9 @@
 	}
 
+
 	do {
 
-		leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
-
+		uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position);
+		uint32_t leaf_block_addr;
     	rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, leaf_block_idx, &leaf_block_addr);
     	if (rc != EOK) {
@@ -419,4 +409,5 @@
     	}
 
+    	block_t *leaf_block;
 		rc = block_get(&leaf_block, fs->device, leaf_block_addr, BLOCK_FLAGS_NONE);
 		if (rc != EOK) {
@@ -424,5 +415,7 @@
 		}
 
-		rc = ext4_dirextory_dx_find_dir_entry(leaf_block, fs->superblock, len, name,
+		aoff64_t block_offset;
+		ext4_directory_entry_ll_t *res_dentry;
+		rc = ext4_directory_dx_find_dir_entry(leaf_block, fs->superblock, len, name,
 				&res_dentry, &block_offset);
 
Index: uspace/lib/ext4/libext4_filesystem.c
===================================================================
--- uspace/lib/ext4/libext4_filesystem.c	(revision b7e02600e8909779146953116f68cafa8e244b48)
+++ uspace/lib/ext4/libext4_filesystem.c	(revision d9bbe45b59b45f91fb35394b54013cbf7aab5774)
@@ -44,8 +44,4 @@
 {
 	int rc;
-	ext4_superblock_t *temp_superblock;
-	size_t block_size;
-	uint32_t block_ids_per_block;
-	int i;
 
 	fs->device = service_id;
@@ -58,4 +54,5 @@
 
 	/* Read superblock from device */
+	ext4_superblock_t *temp_superblock;
 	rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
 	if (rc != EOK) {
@@ -65,5 +62,5 @@
 
 	/* Read block size from superblock and check */
-	block_size = ext4_superblock_get_block_size(temp_superblock);
+	uint32_t block_size = ext4_superblock_get_block_size(temp_superblock);
 	if (block_size > EXT4_MAX_BLOCK_SIZE) {
 		block_fini(fs->device);
@@ -78,8 +75,8 @@
 	}
 
-	block_ids_per_block = block_size / sizeof(uint32_t);
+	uint32_t block_ids_per_block = block_size / sizeof(uint32_t);
 	fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
 	fs->inode_blocks_per_level[0] = 1;
-	for (i = 1; i < 4; i++) {
+	for (int i = 1; i < 4; i++) {
 		fs->inode_blocks_per_level[i] = fs->inode_blocks_per_level[i-1] *
 		    block_ids_per_block;
@@ -97,4 +94,5 @@
 {
 	int rc = EOK;
+
 	if (write_sb) {
 		rc = ext4_superblock_write_direct(fs->device, fs->superblock);
@@ -149,23 +147,19 @@
 {
 	int rc;
-	aoff64_t block_id;
-	uint32_t descriptors_per_block;
-	size_t offset;
-	ext4_block_group_ref_t *newref;
-
-	newref = malloc(sizeof(ext4_block_group_ref_t));
+
+	ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t));
 	if (newref == NULL) {
 		return ENOMEM;
 	}
 
-	descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
+	uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
 	    / ext4_superblock_get_desc_size(fs->superblock);
 
 	/* Block group descriptor table starts at the next block after superblock */
-	block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
+	aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
 
 	/* Find the block containing the descriptor we are looking for */
 	block_id += bgid / descriptors_per_block;
-	offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
+	uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
 
 	rc = block_get(&newref->block, fs->device, block_id, 0);
@@ -201,22 +195,12 @@
 {
 	int rc;
-	aoff64_t block_id;
-	uint32_t block_group;
-	uint32_t offset_in_group;
-	uint32_t byte_offset_in_group;
-	size_t offset_in_block;
-	uint32_t inodes_per_group;
-	uint32_t inode_table_start;
-	uint16_t inode_size;
-	uint32_t block_size;
-	ext4_block_group_ref_t *bg_ref;
-	ext4_inode_ref_t *newref;
-
-	newref = malloc(sizeof(ext4_inode_ref_t));
+
+	ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t));
 	if (newref == NULL) {
 		return ENOMEM;
 	}
 
-	inodes_per_group = ext4_superblock_get_inodes_per_group(fs->superblock);
+	uint32_t inodes_per_group =
+			ext4_superblock_get_inodes_per_group(fs->superblock);
 
 	/* inode numbers are 1-based, but it is simpler to work with 0-based
@@ -224,7 +208,8 @@
 	 */
 	index -= 1;
-	block_group = index / inodes_per_group;
-	offset_in_group = index % inodes_per_group;
-
+	uint32_t block_group = index / inodes_per_group;
+	uint32_t offset_in_group = index % inodes_per_group;
+
+	ext4_block_group_ref_t *bg_ref;
 	rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
 	if (rc != EOK) {
@@ -233,5 +218,5 @@
 	}
 
-	inode_table_start = ext4_block_group_get_inode_table_first_block(
+	uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block(
 	    bg_ref->block_group, fs->superblock);
 
@@ -242,12 +227,9 @@
 	}
 
-	inode_size = ext4_superblock_get_inode_size(fs->superblock);
-	block_size = ext4_superblock_get_block_size(fs->superblock);
-
-	byte_offset_in_group = offset_in_group * inode_size;
-
-	block_id = inode_table_start + (byte_offset_in_group / block_size);
-	offset_in_block = byte_offset_in_group % block_size;
-
+	uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock);
+	uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
+	uint32_t byte_offset_in_group = offset_in_group * inode_size;
+
+	aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size);
 	rc = block_get(&newref->block, fs->device, block_id, 0);
 	if (rc != EOK) {
@@ -256,4 +238,5 @@
 	}
 
+	uint32_t offset_in_block = byte_offset_in_group % block_size;
 	newref->inode = newref->block->data + offset_in_block;
 	/* we decremented index above, but need to store the original value
@@ -322,10 +305,9 @@
 {
 	int rc;
+
 	// release all indirect blocks
 
-	uint32_t fblock;
-
 	// 1) Single indirect
-	fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);
+	uint32_t fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);
 	if (fblock != 0) {
 		rc = ext4_balloc_free_block(fs, inode_ref, fblock);
@@ -437,7 +419,4 @@
 		ext4_inode_ref_t *inode_ref, aoff64_t new_size)
 {
-	aoff64_t old_size;
-	aoff64_t size_diff;
-
 	if (! ext4_inode_can_truncate(fs->superblock, inode_ref->inode)) {
 		// Unable to truncate
@@ -445,16 +424,9 @@
 	}
 
-	old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
-
+	aoff64_t old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
 	if (old_size == new_size) {
 		// Nothing to do
 		return EOK;
 	}
-
-	uint32_t block_size;
-	uint32_t blocks_count, total_blocks;
-	uint32_t i;
-
-	block_size  = ext4_superblock_get_block_size(fs->superblock);
 
 	if (old_size < new_size) {
@@ -465,11 +437,12 @@
 	}
 
-	size_diff = old_size - new_size;
-	blocks_count = size_diff / block_size;
+	aoff64_t size_diff = old_size - new_size;
+	uint32_t block_size  = ext4_superblock_get_block_size(fs->superblock);
+	uint32_t blocks_count = size_diff / block_size;
 	if (size_diff % block_size != 0) {
 		blocks_count++;
 	}
 
-	total_blocks = old_size / block_size;
+	uint32_t total_blocks = old_size / block_size;
 	if (old_size % block_size != 0) {
 		total_blocks++;
@@ -477,5 +450,5 @@
 
 	// starting from 1 because of logical blocks are numbered from 0
-	for (i = 1; i <= blocks_count; ++i) {
+	for (uint32_t i = 1; i <= blocks_count; ++i) {
 		// TODO check retval
 		ext4_filesystem_release_inode_block(fs, inode_ref, total_blocks - i);
@@ -493,10 +466,7 @@
 {
 	int rc;
-	uint32_t offset_in_block;
+
+
 	uint32_t current_block;
-	aoff64_t block_offset_in_level;
-	int i;
-	int level;
-	block_t *block;
 
 	/* Handle inode using extents */
@@ -517,6 +487,6 @@
 
 	/* Determine the indirection level needed to get the desired block */
-	level = -1;
-	for (i = 1; i < 4; i++) {
+	int level = -1;
+	for (int i = 1; i < 4; i++) {
 		if (iblock < fs->inode_block_limits[i]) {
 			level = i;
@@ -530,7 +500,7 @@
 
 	/* Compute offsets for the topmost level */
-	block_offset_in_level = iblock - fs->inode_block_limits[level-1];
+	aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
 	current_block = ext4_inode_get_indirect_block(inode, level-1);
-	offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
+	uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
 
 	if (current_block == 0) {
@@ -538,4 +508,6 @@
 		return EOK;
 	}
+
+	block_t *block;
 
 	/* Navigate through other levels, until we find the block number
@@ -584,13 +556,6 @@
 		ext4_inode_ref_t *inode_ref, aoff64_t iblock, uint32_t fblock)
 {
-
-	int rc;
-	uint32_t offset_in_block;
-	uint32_t current_block, new_block_addr;
-	uint32_t block_size;
-	aoff64_t block_offset_in_level;
-	int i;
-	int level;
-	block_t *block, *new_block;
+	int rc;
+
 
 	/* Handle inode using extents */
@@ -609,6 +574,6 @@
 
 	/* Determine the indirection level needed to get the desired block */
-	level = -1;
-	for (i = 1; i < 4; i++) {
+	int level = -1;
+	for (int i = 1; i < 4; i++) {
 		if (iblock < fs->inode_block_limits[i]) {
 			level = i;
@@ -621,10 +586,15 @@
 	}
 
-	block_size = ext4_superblock_get_block_size(fs->superblock);
+
+
+	uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
 
 	/* Compute offsets for the topmost level */
-	block_offset_in_level = iblock - fs->inode_block_limits[level-1];
-	current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
-	offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
+	aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
+	uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
+	uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
+
+	uint32_t new_block_addr;
+	block_t *block, *new_block;
 
 	if (current_block == 0) {
@@ -634,5 +604,4 @@
 			EXT4FS_DBG("error in allocation");
 		}
-//		EXT4FS_DBG("AAA: new addr \%u, level = \%u", new_block_addr, level);
 
 		ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr);
@@ -677,5 +646,4 @@
 				EXT4FS_DBG("allocation error");
 			}
-//			EXT4FS_DBG("BBB: new addr \%u, offset = \%u, level = \%u", new_block_addr, offset_in_block, level);
 
 			rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
@@ -730,15 +698,11 @@
 {
 	int rc;
+
+
+	/* TODO handle extents */
+
+
 	uint32_t fblock;
-	int i;
-	int level;
-	aoff64_t block_offset_in_level;
-	uint32_t current_block;
-	uint32_t offset_in_block;
-	block_t *block;
 	ext4_inode_t *inode = inode_ref->inode;
-
-	/* TODO handle extents */
-
 
 	/* Handle simple case when we are dealing with direct reference */
@@ -756,6 +720,6 @@
 
 	/* Determine the indirection level needed to get the desired block */
-	level = -1;
-	for (i = 1; i < 4; i++) {
+	int level = -1;
+	for (int i = 1; i < 4; i++) {
 		if (iblock < fs->inode_block_limits[i]) {
 			level = i;
@@ -769,11 +733,12 @@
 
 	/* Compute offsets for the topmost level */
-	block_offset_in_level = iblock - fs->inode_block_limits[level-1];
-	current_block = ext4_inode_get_indirect_block(inode, level-1);
-	offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
+	aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
+	uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1);
+	uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
 
 	/* Navigate through other levels, until we find the block number
 	 * or find null reference meaning we are dealing with sparse file
 	 */
+	block_t *block;
 	while (level > 0) {
 		rc = block_get(&block, fs->device, current_block, 0);
Index: uspace/lib/ext4/libext4_ialloc.c
===================================================================
--- uspace/lib/ext4/libext4_ialloc.c	(revision b7e02600e8909779146953116f68cafa8e244b48)
+++ uspace/lib/ext4/libext4_ialloc.c	(revision d9bbe45b59b45f91fb35394b54013cbf7aab5774)
@@ -59,7 +59,6 @@
 {
 	int rc;
+
 	uint32_t block_group = ext4_ialloc_get_bgid_of_inode(
-			fs->superblock, inode_ref->index);
-	uint32_t index_in_group = ext4_ialloc_inode2index_in_group(
 			fs->superblock, inode_ref->index);
 
@@ -80,4 +79,6 @@
 	}
 
+	uint32_t index_in_group = ext4_ialloc_inode2index_in_group(
+				fs->superblock, inode_ref->index);
 	ext4_bitmap_free_bit(bitmap_block->data, index_in_group);
 	bitmap_block->dirty = true;
Index: uspace/lib/ext4/libext4_inode.c
===================================================================
--- uspace/lib/ext4/libext4_inode.c	(revision b7e02600e8909779146953116f68cafa8e244b48)
+++ uspace/lib/ext4/libext4_inode.c	(revision d9bbe45b59b45f91fb35394b54013cbf7aab5774)
@@ -160,10 +160,8 @@
 uint64_t ext4_inode_get_blocks_count(ext4_superblock_t *sb, ext4_inode_t *inode)
 {
-	uint64_t count;
-
 	if (ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
 
 		/* 48-bit field */
-		count = ((uint64_t)uint16_t_le2host(inode->osd2.linux2.blocks_high)) << 32 |
+		uint64_t count = ((uint64_t)uint16_t_le2host(inode->osd2.linux2.blocks_high)) << 32 |
 				uint32_t_le2host(inode->blocks_count_lo);
 
@@ -283,24 +281,17 @@
 uint32_t ext4_inode_get_extent_block(ext4_inode_t *inode, uint64_t idx, service_id_t service_id)
 {
+	int rc;
+
+	block_t* block = NULL;
+
 	ext4_extent_header_t *header = ext4_inode_get_extent_header(inode);
-	ext4_extent_t *extent;
-	ext4_extent_index_t *extent_index;
-
-	uint32_t first_block;
-	uint16_t block_count;
-	uint64_t phys_block = 0;
-	uint64_t child;
-
-	int rc;
-	block_t* block = NULL;
-
 	while (ext4_extent_header_get_depth(header) != 0) {
 
-		extent_index = EXT4_EXTENT_FIRST_INDEX(header);
+		ext4_extent_index_t *extent_index = EXT4_EXTENT_FIRST_INDEX(header);
 
 		for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) {
-			if(idx >= ext4_extent_index_get_first_block(extent_index)) {
-
-				child = ext4_extent_index_get_leaf(extent_index);
+			if (idx >= ext4_extent_index_get_first_block(extent_index)) {
+
+				uint64_t child = ext4_extent_index_get_leaf(extent_index);
 
 				if (block != NULL) {
@@ -319,20 +310,21 @@
 	}
 
-	extent = EXT4_EXTENT_FIRST(header);
+	ext4_extent_t *extent = EXT4_EXTENT_FIRST(header);
+	uint64_t phys_block = 0;
 
 	for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) {
 
-		first_block = ext4_extent_get_first_block(extent);
-		block_count = ext4_extent_get_block_count(extent);
+		uint32_t first_block = ext4_extent_get_first_block(extent);
+		uint16_t block_count = ext4_extent_get_block_count(extent);
 
 		if ((idx >= first_block) && (idx < first_block + block_count)) {
-			phys_block = ext4_extent_get_start(extent) + idx;
-			phys_block -= ext4_extent_get_first_block(extent);
-
-			// Memory leak prevention
-			if (block != NULL) {
-				block_put(block);
-			}
-			return phys_block;
+			 phys_block = ext4_extent_get_start(extent) + idx;
+			 phys_block -= ext4_extent_get_first_block(extent);
+
+			 // Memory leak prevention
+			 if (block != NULL) {
+				 block_put(block);
+			 }
+			 return phys_block;
 		}
 		// Go to the next extent
Index: uspace/lib/ext4/libext4_superblock.c
===================================================================
--- uspace/lib/ext4/libext4_superblock.c	(revision b7e02600e8909779146953116f68cafa8e244b48)
+++ uspace/lib/ext4/libext4_superblock.c	(revision d9bbe45b59b45f91fb35394b54013cbf7aab5774)
@@ -437,8 +437,7 @@
     ext4_superblock_t **superblock)
 {
-	void *data;
 	int rc;
 
-	data = malloc(EXT4_SUPERBLOCK_SIZE);
+	void *data = malloc(EXT4_SUPERBLOCK_SIZE);
 	if (data == NULL) {
 		return ENOMEM;
@@ -463,6 +462,4 @@
 	int rc;
 	uint32_t phys_block_size;
-	uint64_t first_block;
-	uint32_t block_count;
 
 	rc = block_get_bsize(service_id, &phys_block_size);
@@ -472,6 +469,6 @@
 	}
 
-	first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
-	block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
+	uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
+	uint32_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
 
 	if (EXT4_SUPERBLOCK_SIZE % phys_block_size) {
