Refactoring

Added example and cleaned up js code.