refactored javascript conditional
made controller logic stricter