added log in and fixed bugs