added more functions and refactored..