cleaned up code a bit by reorganizing, added comments; templated login page