Added new features and cleaned up source a bit