added most of rails functionality, badly needs testing