Clean up code
Remove obsolete code
Reduce variables' scopes