Code cleanup and fix login issues

see #270