Refactored, added new functions, etc.