controller secutity and major refactor