Working code (Beautification remaining)