Used Q promises library for more graceful handling of chaining