Cleaned the code. Start point for further tweaks