converted foreman to javascript version