Refactored, added some empty returns to reduce the number of return statements in generated js