Added Flask login and fixed bugs